package dao;

import common.SelectStu;
import common.User;

import service.FlushCourse;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Vector;

public class SelectPeop {
    private static Connection conn=DataBaseConnect.getConn();
    private static String sql="INSERT INTO select_peop (selecttaskid,studentid)VALUES(?,?)";
    private static PreparedStatement pstmt;
    static {
        try {
            pstmt=conn.prepareStatement(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    public static void selectPeop(SelectStu selectStu){
        try {
            pstmt.setString(1,selectStu.getSelect().getId());
            pstmt.setString(2,selectStu.getStudentid());
            //通知 班级成员
            int count= pstmt.executeUpdate();
            if (count == 1) {
                System.out.println("选人成功");
                Vector<User> stu=GetStu.gatStu(selectStu.getSelect().getCourseid());
                for(int i=0;i<stu.size();i++){
                    FlushCourse.flush(stu.get(i).getId());
                }
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
